package Impl;

import dao.IAdminDao;
import entity.AdminMan;
import until.DBuntil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AdminDaoImpl extends DBuntil implements IAdminDao {
    @Override
    public AdminMan login(String name, String pwd) {
        AdminMan admin = null;
        Connection conn = null;
        PreparedStatement pst = null;
        ResultSet rs = null;

        try {
            conn = getConn();
            String sql = "SELECT * FROM TB_ADMIN WHERE COL_NAME=? AND COL_PWD=?";
            pst = conn.prepareStatement(sql);
            pst.setString(1, name);
            pst.setString(2, pwd);
            rs = pst.executeQuery();
            if (rs.next()) {
                admin = new AdminMan();
                admin.setAdminId(rs.getInt(1));
                admin.setAdminName(rs.getString(2));
                admin.setAdminPwd(rs.getString(3));
                admin.setAdminFlag(rs.getInt(4));
                admin.setAdminDel(rs.getInt(5));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            cloAll(conn, pst, rs);
        }

        return admin;
    }
}
